function [D, N] = load_data_ftn(sample, K)          
D.mkt   = sample(:,1); % market index, defined based on (state,year)
D.state = sample(:,2); % numeric state value 
D.year  = sample(:,3); % year 
D.naic  = sample(:,4); % NAIC code
D.major = sample(:,5); % indicator for whether a firm is a major firm vs. merged minor firm
D.id_is = sample(:,6); % identifier based on (insurer, state)
D.id_ps = sample(:,7); % identifier based on (plan, state)
%D.s1_normalized = sample(:,8); 
D.s1    = sample(:,9); % market share 
D.s1_uninsured  = sample(:,10); % uninsured rate 
D.p1    = sample(:,11);     % initial premiums
D.r2    = sample(:,12:12+K-1);     % subsequent premium increases
D.pr_s  = sample(:,12+K:12+K+K-1); % probability of 2nd-period states
D.iv_prem   = sample(:,12+K+K); % prices in all other states
D.n_variety = sample(:,12+K+K+1); % number of plans. 
D.n_insurers = sample(:,12+K+K+2); % number of insurers: always 1 for major, multiple for rep. minor 
D.delta_n_plans_reg = sample(:, 12+K+K+3); % change in # of plans around reg implementation yr
D.delta_premium_reg = sample(:, 12+K+K+4); % change in premiums around reg implementation yr
D.delta_n_insurers_reg = sample(:, 12+K+K+5); % change in # of insurers around reg implementation yr
D.iv_prem_nstate = sample(:,12+K+K+6); % prices in neighboring states
D.reg_year = sample(:,12+K+K+9); % regulation adoption year
D.id_ist = sample(:,12+K+K+10); % identifier for each (insurer,state,year) pair

% predicted 2nd-period claims (5 states)
D.claims2 = sample(:, 12+K+K+14:12+K+K+18);
D.claims_target =  sample(:, 12+K+K+19);

D.iv_nplans_allotherstate = sample(:, 12+K+K+20); % insurers' mean plans in all other states in a given year
D.iv_insurer_active_allotherstate = sample(:, 12+K+K+21); % mean # states where the insurer active in a given year
D.iv_nplans_nstate = sample(:, 12+K+K+22); % insurers' mean plans in neighboring states in a given year
D.iv_insurer_active_nstate = sample(:, 12+K+K+23); % mean # neighboring states where the insurer active in a given year

D.delta_approved_cum = sample(:, 12+K+K+24); % change in approved rate increases of plans sold after vs. around reg implementation

D.sold_after_reg = sample(:, 12+K+K+25); % whether first issued after reg adoption
D.brandnew = sample(:, 12+K+K+26); % dummy for whether first issued in the given year

D.in_regression = sample(:, 12+K+K+27); % dummy for whether used in the event study regression

% compute 2nd-period premium levels
D.p2 = repmat(D.p1,1,K).*(1+0.01*D.r2);

% sample size
N.st  = length(unique(D.mkt)); % # of of markets
N.ist = size(D.mkt,1); % # of observations (insurer-state-year level)
N.i   = length(unique(D.naic));  % # of insurers
N.is  = length(unique(D.id_is)); % # of (insurer,state) pairs
N.ps  = length(unique(D.id_ps)); % # of (plan, state) pairs
N.s   = length(unique(D.state)); % # of states

% indicator of whether all changes in the implementation year are available
% - missing for the same set of observations. 
temp = ~isnan([D.delta_n_plans_reg D.delta_premium_reg D.delta_n_insurers_reg D.delta_approved_cum]); 
ncol_temp = size(temp,2);
temp = sum(temp,2);
D.delta_reg_nm = (temp==ncol_temp);

% save the actual price levels in 2nd period as D.p2_actual
D.p2_actual = D.p2;



